package com.youi.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.GoodsandgoodscarDao;
import com.youi.entity.Goods;
import com.youi.entity.Goodsandgoodscar;
import com.youi.entity.Goodsimgs;
import com.youi.entity.Goodssize;
import com.youi.service.GoodsService;
import com.youi.service.GoodsandgoodscarService;
import com.youi.service.GoodsimgsService;
import com.youi.service.GoodssizeService;

@Service
public class GoodsandgoodscarServiceImpl extends BaseServiceImpl<Goodsandgoodscar> implements GoodsandgoodscarService{
		
		private GoodsandgoodscarDao goodsandgoodscarDao;
		@Autowired
		private GoodsService goodsService;
		@Autowired
		private GoodsimgsService goodsimgsService;
		@Autowired
		private GoodssizeService goodssizeService;
		@Autowired
		public void setfaultRecordDao(GoodsandgoodscarDao goodsandgoodscarDao){
			this.goodsandgoodscarDao=goodsandgoodscarDao;
			super.setBaseDAO(goodsandgoodscarDao);
		}

		@Override
		public List<Goodsandgoodscar> getGoodsandgoodscar(List<Goodsandgoodscar> goodsandgoodscarList) {
			// TODO Auto-generated method stub
			if (goodsandgoodscarList!=null&&goodsandgoodscarList.size()>0) {
				for (Goodsandgoodscar goodsandgoodscar : goodsandgoodscarList) {
					Goods goods=goodsService.get(goodsandgoodscar.getGoodsId());
					if (goods!=null) {
						Map<String, Object> params=new HashMap<String, Object>();
						params.put(Common.DELSTATUS, DelStatus.NODEL);
						params.put("goodsId", goods.getId());
						params.put(Common.TYPE,1);
						Goodsimgs goodsimgs=goodsimgsService.getByParam(params);
						goodsandgoodscar.setGoodsImg(goodsimgs.getImgs());
						params=new HashMap<String, Object>();
						params.put(Common.DELSTATUS, DelStatus.NODEL);
						params.put("goodsId", goods.getId());
						params.put(Common.ID, goodsandgoodscar.getGoodssizeId());
						Goodssize goodssize=goodssizeService.getByParam(params);
						if (goodssize!=null) {
							goodsandgoodscar.setGoodsPeice(goodssize.getPrice());							
							goodsandgoodscar.setMaxStockNum(goodssize.getStockNum());
						}
						goodsandgoodscar.setGoods(goods);
					}
					
				}
			}
			return goodsandgoodscarList;
		}
}